﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MrBrooks.Utility
{
    /// <summary>
    /// 检测工具
    /// </summary>
    public static class CheckTools
    {
        /// <summary>
        /// 检测值是否存在
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static bool CheckExists(int source, params int[] target)
        {
            foreach (var t in target)
            {
                if (source == t) return true;
            }
            return false;
        }

        /// <summary>
        /// 是否有空参数
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool CheckExistsEmpty(params string[] source)
        {
            foreach (var t in source)
            {
                if (string.IsNullOrWhiteSpace(t)) return true;
            }

            return false;
        }

        /// <summary>
        /// 检测是否含有空对象
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool CheckExistsNull(params object[] source)
        {
            foreach (var tmp in source)
            {
                if (tmp == null) return true;
            }

            return false;
        }

        /// <summary>
        /// 检查是否所有参数都为正整数
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool CheckPositive(params int[] source)
        {
            foreach (var tmp in source)
            {
                if (tmp <= 0) return false;
            }

            return true;
        }

        /// <summary>
        /// 实现 Contains 的模糊查询
        /// </summary>
        /// <param name="source"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool ContainsKey(this string source, string key)
        {
            return source.ToUpper().Contains(key.ToUpper());
        }
    }
}
